<?php
namespace module\home\model;

use \DataModel;
require_once APP_DIR . '/library/DataModel.php';

/**
 * Profile Model class 
 *
 * @package yasns
 * @subpackage model
 */
class Profile extends DataModel
{
	protected
	   $_table = 'profile',
	   $_pk = 'profile_id';

	
	/**
	 * Retrieve profile data model based on account id
	 * 
	 * @param int $account_id accound id of the profile
	 * @return DataModel 
	 */
	public static function findProfileByAccountId($account_id)
	{
		$conn = DataModel::getConnection();
		$table = "profile";
		$field = "account_id";
		
		$stmt = $conn->prepare(	"select * from {$table} " . 
										"where {$field} = ?");
										
		$stmt->execute( array($account_id) );
		$row = $stmt->fetch();
			
		if (!$row) $profile = null;
		else {
			$profile = new Profile();
			$profile->setData($row);
		}
		return $profile;
	}

	/**
	 * Retrieve account data based on account id
	 * 
	 * @param int $account_id primary key
	 * @return DataModel 
	 */
	public static function getAccountModel($account_id)
	{
		$conn = DataModel::getConnection();
		$table = "account";
		$field = "account_id";

		$stmt = $conn->prepare( "select * from {$table} ".
										"where {$field} = ?");
		$stmt->execute( array($account_id) );
		$row = $stmt->fetch();
		
		return $row;
	}

}
?>
